﻿using System;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Reflection;
namespace Data
{
    //LotteryAnnouncement
    public class LotteryAnnouncement
    {
        /// <summary>
        /// 主键
        /// </summary>
        private readonly string primaryKey = "id";
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public long Add(Model.LotteryAnnouncement model)
        {
            return new DataAccess().Add<Model.LotteryAnnouncement>(model, primaryKey);
        }
        //wlq20151112
        public List<Model.LotteryAnnouncement> GetListByTypeWeek(int PageIndex, int PageSize, int type, int WeekNumber, out int totalCount)
        {
            string strWhere = " LotteryType =" + type + " and datepart(weekday,openTime)=" + WeekNumber;//周二，四，日，走势，分别对应WeekNumber：3,5,1
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetListByTypeWeek1(int PageIndex, int PageSize, int type, int WeekNumber, out int totalCount)
        {
            DateTime dt = DateTime.Now;
            string currentYear = dt.Year.ToString();
            string strWhere = " LotteryType =" + type + " and datepart(weekday,openTime)=" + WeekNumber;//周二，四，日，走势，分别对应WeekNumber：3,5,1
            strWhere = strWhere + " and DATEPART(YEAR,openTime)='" + currentYear + "'";
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " asc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetListByShuangseDSqi(int PageIndex, int PageSize, int type, int dsQi, out int totalCount)
        {
           
            string strWhere = " LotteryType =" + type + " and LotteryQS% 2=" + dsQi;//单双期 当dsQi为0时则为双期，为1则为单期
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetListByShuangseDSqi1(int PageIndex, int PageSize, int type, int dsQi, out int totalCount)
        {
            DateTime dt = DateTime.Now;
            string currentYear = dt.Year.ToString();
            string strWhere = " LotteryType =" + type + " and LotteryQS% 2=" + dsQi;//单双期 当dsQi为0时则为双期，为1则为单期
            strWhere = strWhere + " and DATEPART(YEAR,openTime)='" + currentYear + "'";
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " asc", strWhere);
        }
        //wlq20151112
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update(Model.LotteryAnnouncement model)
        {
            return new DataAccess().Update<Model.LotteryAnnouncement>(model, primaryKey);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public bool Delete(long Id)
        {
            return new DataAccess().Delete<Model.LotteryAnnouncement>(Id, primaryKey);
        }
        /// <summary>
        /// 单条
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public Model.LotteryAnnouncement GetModel(long Id)
        {
            return new DataAccess().Get<Model.LotteryAnnouncement>(Id, primaryKey);
        }
        public Model.LotteryAnnouncement GetModelByLotteryAnnouncementid(long LotteryAnnouncementid)
        {
            return new DataAccess().Get<Model.LotteryAnnouncement>(LotteryAnnouncementid, "LotteryAnnouncementid");
        }


        public Model.LotteryAnnouncement GetModelBysql(string sql)
        {
            return new DataAccess().Get<Model.LotteryAnnouncement>(sql);
        }
        /// <summary>
        /// 总数据数
        /// </summary>
        /// <returns></returns>
        public int GetAll_Count()
        {
            return new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey);
        }
        public int GetAll_Count(string whereStr)
        {
            return new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, whereStr);
        }
        /// <summary>
        /// 抽取分页数据
        /// </summary>
        public List<Model.LotteryAnnouncement> GetPageList_Where(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {
            string strWhere = GetSqlWhere(newsclassid);
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, " LotteryQS desc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetPageList_Where1(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {
            DateTime dt = DateTime.Now;
            string currentYear = dt.Year.ToString();
            string strWhere = GetSqlWhere(newsclassid);
            strWhere = strWhere + " and DATEPART(YEAR,openTime)='" + currentYear + "'";
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, " LotteryQS asc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetPageList_Where2(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {
            DateTime dt = DateTime.Now;
            string currentYear = dt.Year.ToString();
            string strWhere = GetSqlWhere(newsclassid);
            strWhere = strWhere + " and DATEPART(YEAR,openTime)='" + currentYear + "'";
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, " LotteryQS desc", strWhere);
        }
        public List<Model.LotteryAnnouncement> GetListByTypeQs(int PageIndex, int PageSize, int type, string qs, out int totalCount)
        {
            string strWhere = " LotteryType =" + type + " and LotteryQS=" + qs;
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere);
        }
        public DataTable GetPageDT_Where(int PageIndex, int PageSize, long newsclassid, out int totalCount)
        {
            string strWhere = GetSqlWhere(newsclassid);
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, strWhere);
            return ConvertHelper<Model.LotteryAnnouncement>.ConvertToDT(new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", strWhere));
        }
        public List<Model.LotteryAnnouncement> GetPageListSQl(int PageIndex, int PageSize, string sql, out int totalCount)
        {
            totalCount = new DataAccess().GetCount<Model.LotteryAnnouncement>(primaryKey, sql);
            return new DataAccess().GetPage_List<Model.LotteryAnnouncement>(PageIndex, PageSize, primaryKey, primaryKey + " desc", sql);
        }
        /// <summary>
        /// 拼接条件
        /// </summary>
        public string GetSqlWhere(long newsclassid)
        {
            StringBuilder sqlWhere = new StringBuilder();

            sqlWhere.Append(" 1>0");

            if (newsclassid > 0)
            {
                sqlWhere.Append(" and LotteryType =" + newsclassid);
            }
            return sqlWhere.ToString();
        }
        /// <summary>
        /// 批删
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public int Drop(string Ids)
        {
            return new DataAccess().Drop<Model.LotteryAnnouncement>(Ids, primaryKey);
        }
        //--------------------------------------------------扩展方法
        public DataTable GetPageListBysql(string sql)
        {
            return DbHelp.ExecuteDataset(DBConfig.ConnectionSettings, CommandType.Text, sql, null).Tables[0];
        }

        public List<Model.LotteryAnnouncement> GetList(string Sql)
        {
            return new DataAccess().GetList<Model.LotteryAnnouncement>(Sql);
        }


        public static List<Model.LotteryAnnouncement> GetListOrderBy(string OrderBy, string WhereStr)
        {
            return new DataAccess().GetListOrderBy<Model.LotteryAnnouncement>(OrderBy, WhereStr);
        }

        public List<Model.LotteryAnnouncement> GetListOrderBy(string OrderBy, string WhereStr, string topStr, string ColumnNmae)
        {
            return new DataAccess().GetListOrderBy<Model.LotteryAnnouncement>(OrderBy, WhereStr, topStr, ColumnNmae);
        }


        //public Model.LotteryBuyDetail GetModelBysql(string sql)
        //{
        //    return new DataAccess().Get<Model.LotteryBuyDetail>(sql);
        //}

    }
}